﻿using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace SKN
{
    /// <summary>
    /// Contains common method for Webpart
    /// </summary>
    public class Alerts
    {
        /// <summary>
        /// Use this method to quickly set a new Alert template for any list
        /// </summary>
        /// <param name="web"></param>
        /// <param name="listName"></param>
        /// <param name="alertTemplateName"></param>
        /// <example>Alerts.SetAlertTemplate(web,"Shared Documents","AlertTemplate.SpecialList");</example>
        public static void SetAlertTemplate(SPWeb web, string listName, string alertTemplateName)
        {
            SPList list = web.Lists[listName];

            var ats = new SPAlertTemplateCollection((SPWebService) (web.Site.WebApplication.Parent));
            list.AlertTemplate = ats[alertTemplateName];
            list.Update();
        }
    }
}